<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="tong.li&#39;s blog">
  <meta name="keyword" content="彤哥哥博客，95后技术爱好者,现就职于同程旅行/同程艺龙上海分公司，专注于互联网技术分享的平台。">
  
    <link rel="shortcut icon" href="/css/images/icon.png">
  
  <title>
    
      Linux基础-wget与curl命令 | 彤哥哥的博客
    
  </title>
  <link href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="https://cdn.staticfile.org/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="https://cdn.staticfile.org/highlight.js/9.12.0/styles/tomorrow-night.min.css" rel="stylesheet">
  
<link rel="stylesheet" href="/css/style.css">

  
  <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdn.staticfile.org/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="https://cdn.staticfile.org/nprogress/0.2.0/nprogress.min.js"></script>
  
    
<script src="/js/qrious.js"></script>

  
  
  
  
    <!-- MathJax support START -->
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="https://cdn.staticfile.org/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <!-- MathJax support END -->
  


  
  
    
<script src="/js/local-search.js"></script>


<meta name="generator" content="Hexo 5.4.2"></head>
<div class="wechat-share">
  <img src="/css/images/logo.png" />
</div>
  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/">
      <div class="logo"></div>
      <span>彤哥哥的博客</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/" class="item-link">主页</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/series/" class="item-link">分类</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/tags/" class="item-link">标签</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/archives/" class="item-link">归档</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/project/" class="item-link">项目</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/about/" class="item-link">关于</a>
          
        </li>
      
      
        <li class="menu-item menu-item-search right-list">
    <a role="button" class="popup-trigger">
        <i class="fa fa-search fa-fw"></i>
    </a>
</li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/" class="menu-link">主页</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/series/" class="menu-link">分类</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/tags/" class="menu-link">标签</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/archives/" class="menu-link">归档</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/project/" class="menu-link">项目</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/about/" class="menu-link">关于</a>
            
          </li>
        
      </ul>
    </div>
    
      <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
            <span class="search-icon">
                <i class="fa fa-search"></i>
            </span>
            <div class="search-input-container">
                <input autocomplete="off" autocapitalize="off"
                    placeholder="Please enter your keyword(s) to search." spellcheck="false"
                    type="search" class="search-input">
            </div>
            <span class="popup-btn-close">
                <i class="fa fa-times-circle"></i>
            </span>
        </div>
        <div id="search-result">
            <div id="no-result">
                <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
            </div>
        </div>
    </div>
</div>
    
  </div>
</header>

    <div id="article-banner">
  <h2>Linux基础-wget与curl命令</h2>
  <p class="post-date">2018-05-22</p>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><h2 id="Linux系统下的下载工具"><a href="#Linux系统下的下载工具" class="headerlink" title="Linux系统下的下载工具"></a>Linux系统下的下载工具</h2><p>wget 是一个从网络上自动下载文件的自由工具,支持通过 HTTP,HTTPS,FTP 三个最常见的 TCP/IP协议 下载,并可以使用 HTTP 代理.”wget” 这个名称来源于 “World Wide Web” 与 “get” 的结合.<br>所谓自动下载,是指 wget 可以在用户退出系统的之后在继续后台执行,直到下载任务完成.  </p>
<h3 id="命令选项"><a href="#命令选项" class="headerlink" title="命令选项"></a>命令选项</h3><ul>
<li>-a&lt;日志文件&gt;:在指定的日志文件中记录资料的执行过程;  </li>
<li>-A&lt;后缀名&gt;:指定要下载文件的后缀名,多个后缀名之间使用逗号进行分隔;  </li>
<li>-b:进行后台的方式运行wget;  </li>
<li>-B&lt;连接地址&gt;:设置参考的连接地址的基地地址;  </li>
<li>-c:继续执行上次终端的任务,断点续传;  </li>
<li>-C&lt;标志&gt;:设置服务器数据块功能标志on为激活,off为关闭,默认值为on;  </li>
<li>-d:调试模式运行指令;  </li>
<li>-D&lt;域名列表&gt;:设置顺着的域名列表,域名之间用”,”分隔;  </li>
<li>-e&lt;指令&gt;:作为文件”.wgetrc”中的一部分执行指定的指令;  </li>
<li>-h:显示指令帮助信息;  </li>
<li>-i&lt;文件&gt;:从指定文件获取要下载的URL地址;  </li>
<li>-l&lt;目录列表&gt;:设置顺着的目录列表,多个目录用”,”分隔;  </li>
<li>-L:仅顺着关联的连接;  </li>
<li>-O: 将要下载的文件进行重命名</li>
<li>-r:递归下载方式;  </li>
<li>-nc:文件存在时,下载文件不覆盖原有文件;  </li>
<li>-nv:下载时只显示更新和出错信息,不显示指令的详细执行过程;  </li>
<li>-q:不显示指令执行过程;  </li>
<li>-nh:不查询主机名称;  </li>
<li>-v:显示详细执行过程; </li>
<li>-V:显示版本信息;  </li>
<li>–passive-ftp:使用被动模式PASV连接FTP服务器;  </li>
<li>–follow-ftp:从HTML文件中下载FTP连接文件.  <h3 id="参考示例"><a href="#参考示例" class="headerlink" title="参考示例"></a>参考示例</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">1.下载网络资源</span><br><span class="line">[root@litong ~]# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz   #使用wget下载Python安装包</span><br><span class="line">--2018-05-22 16:57:49--  https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz</span><br><span class="line">Resolving www.python.org (www.python.org)... 151.101.8.223, 2a04:4e42:2::223</span><br><span class="line">Connecting to www.python.org (www.python.org)|151.101.8.223|:443... connected.</span><br><span class="line">HTTP request sent, awaiting response... 200 OK</span><br><span class="line">Length: 22994617 (22M) [application/octet-stream]</span><br><span class="line">Saving to: ‘Python-3.6.5.tgz’</span><br><span class="line"></span><br><span class="line">100%[=============================================================================================================&amp;gt;] 22,994,617  27.6MB/s   in 0.8s   </span><br><span class="line"></span><br><span class="line">2018-05-22 16:57:50 (27.6 MB/s) - ‘Python-3.6.5.tgz’ saved [22994617/22994617]</span><br><span class="line"></span><br><span class="line">[root@litong ~]# ll | grep Python</span><br><span class="line">-rw-r--r-- 1 root root 22994617 Mar 28 18:24 Python-3.6.5.tgz</span><br></pre></td></tr></table></figure></li>
</ul>
<p>2.断点续传  </p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">[root@litong ~]# wget -c http://d1.music.126.net/dmusic/netease-cloud-music_1.1.0_amd64_ubuntu.deb  #下载Linux版本的网易云音乐</span><br><span class="line">--2018-05-22 17:04:04--  http://d1.music.126.net/dmusic/netease-cloud-music_1.1.0_amd64_ubuntu.deb</span><br><span class="line">Resolving d1.music.126.net (d1.music.126.net)... 157.185.168.24</span><br><span class="line">Connecting to d1.music.126.net (d1.music.126.net)|157.185.168.24|:80... connected.</span><br><span class="line">HTTP request sent, awaiting response... 200 OK</span><br><span class="line">Length: 68515076 (65M) [application/octet-stream]</span><br><span class="line">Saving to: ‘netease-cloud-music_1.1.0_amd64_ubuntu.deb’</span><br><span class="line">46% [====================================================================&amp;gt;                                                                                 ] 31,560,638  15.2MB/s             ^C           #按下Ctrl+C终止下载</span><br><span class="line">[root@litong ~]# wget -c http://d1.music.126.net/dmusic/netease-cloud-music_1.1.0_amd64_ubuntu.deb  #端点续传,继续下载,不会重新下载</span><br><span class="line">--2018-05-22 17:04:09--  http://d1.music.126.net/dmusic/netease-cloud-music_1.1.0_amd64_ubuntu.deb</span><br><span class="line">Resolving d1.music.126.net (d1.music.126.net)... 157.185.168.24</span><br><span class="line">Connecting to d1.music.126.net (d1.music.126.net)|157.185.168.24|:80... connected.</span><br><span class="line">HTTP request sent, awaiting response... 206 Partial Content</span><br><span class="line">Length: 68515076 (65M), 33805218 (32M) remaining [application/octet-stream]</span><br><span class="line">Saving to: ‘netease-cloud-music_1.1.0_amd64_ubuntu.deb’</span><br><span class="line">100%[+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++==========================================================================&amp;gt;] 68,515,076  14.7MB/s   in 2.2s   </span><br><span class="line">Last-modified header invalid -- time-stamp ignored.</span><br><span class="line">2018-05-22 17:04:12 (14.7 MB/s) - ‘netease-cloud-music_1.1.0_amd64_ubuntu.deb’ saved [68515076/68515076]</span><br></pre></td></tr></table></figure>
<p>3.后台下载</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">[root@litong ~]# wget -b https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz &amp;&amp; tail -50f wget-log  #后台下载并查看下载日志.下载并不阻塞Shell交互</span><br><span class="line">Continuing in background, pid 301.</span><br><span class="line">Output will be written to ‘wget-log’.</span><br><span class="line">--2018-05-22 17:14:55--  https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz</span><br><span class="line">Resolving www.python.org (www.python.org)... 151.101.8.223, 2a04:4e42:2::223</span><br><span class="line">Connecting to www.python.org (www.python.org)|151.101.8.223|:443... connected.</span><br><span class="line">HTTP request sent, awaiting response... 200 OK</span><br><span class="line">Length: 22994617 (22M) [application/octet-stream]</span><br><span class="line">Saving to: ‘Python-3.6.5.tgz’</span><br><span class="line">0K     .......... .......... .......... .......... ..........  0% 17.2M 1s</span><br><span class="line">50K    .......... .......... .......... .......... ..........  0% 23.7M 1s</span><br><span class="line">100K   .......... .......... .......... .......... ..........  0% 33.3M 1s</span><br><span class="line">150K   .......... .......... .......... .......... ..........  0% 22.4M 1s</span><br><span class="line">200K   .......... .......... .......... .......... ..........  1% 34.5M 1s</span><br><span class="line">250K   .......... .......... .......... .......... ..........  1% 32.9M 1s</span><br><span class="line">       .......... .......... .......... .......... ..........</span><br><span class="line">22250K .......... .......... .......... .......... .......... 99% 13.2M 0s</span><br><span class="line">22300K .......... .......... .......... .......... .......... 99% 10.7M 0s</span><br><span class="line">22350K .......... .......... .......... .......... .......... 99% 12.4M 0s</span><br><span class="line">22400K .......... .......... .......... .......... .......... 99% 14.3M 0s</span><br><span class="line">22450K .....                                                 100%  129M=0.8s</span><br><span class="line">2018-05-22 17:14:56 (27.7 MB/s) - ‘Python-3.6.5.tgz’ saved [22994617/22994617]   </span><br></pre></td></tr></table></figure>
<h2 id="测试接口常用的curl"><a href="#测试接口常用的curl" class="headerlink" title="测试接口常用的curl"></a>测试接口常用的curl</h2><p>curl是利用URL语法在命令行方式下工作的开源文件传输工具.它支持文件的上传和下载,所以是综合传输工具.<br>curl支持包括HTTP,HTTPS,ftp等众多协议,还支持POST,cookies认证,从指定偏移处下载部分文件,用户代理字符串,限速,文件大小,进度条等特征.做网页处理流程和数据检索自动化,curl可以祝一臂之力.    </p>
<h3 id="参考示例-1"><a href="#参考示例-1" class="headerlink" title="参考示例"></a>参考示例</h3><p>1.简单请求</p>
<figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@litong ~]# curl https://www.baidu.<span class="keyword">com</span>  #简单GET请求请求百度</span><br><span class="line">&amp;<span class="keyword">lt</span>;!DOCTYPE html&amp;gt;</span><br><span class="line">&amp;<span class="keyword">lt</span>;!--STATUS OK--&amp;gt;&amp;<span class="keyword">lt</span>;html&amp;gt; &amp;<span class="keyword">lt</span>;head&amp;gt;&amp;<span class="keyword">lt</span>;meta http-equiv=content-<span class="built_in">type</span> content=text/html;charset=utf-<span class="number">8</span>&amp;gt;&amp;<span class="keyword">lt</span>;meta http-equiv=<span class="keyword">X</span>-UA-Compatible content=IE=Edge&amp;gt;&amp;<span class="keyword">lt</span>;meta content=always name=referrer&amp;gt;&amp;<span class="keyword">lt</span>;link rel=stylesheet <span class="built_in">type</span>=text/css href=https://ss1.bdstatic.<span class="keyword">com</span>/<span class="number">5</span>eN1bjq8AAUYm2zgoY3K/r/www/cache/bdorz/baidu.<span class="built_in">min</span>.css&amp;gt;&amp;<span class="keyword">lt</span>;title&amp;gt;百度一下,你就知道&amp;<span class="keyword">lt</span>;/title&amp;gt;&amp;<span class="keyword">lt</span>;/head&amp;gt; &amp;<span class="keyword">lt</span>;body link=#<span class="number">0000</span><span class="keyword">cc</span>&amp;gt; &amp;<span class="keyword">lt</span>;div id=wrapper&amp;gt; &amp;<span class="keyword">lt</span>;div id=head&amp;gt; &amp;<span class="keyword">lt</span>;div class=head_wrapper&amp;gt; &amp;<span class="keyword">lt</span>;div class=s_form&amp;gt; &amp;<span class="keyword">lt</span>;div class=s_form_wrapper&amp;gt; &amp;<span class="keyword">lt</span>;div id=<span class="keyword">lg</span>&amp;gt; &amp;<span class="keyword">lt</span>;img hidefocus=true src=//www.baidu.<span class="keyword">com</span>/img/bd_logo1.png width=<span class="number">270</span> height=<span class="number">129</span>&amp;gt; &amp;<span class="keyword">lt</span>;/div&amp;gt; &amp;<span class="keyword">lt</span>;form id=form name=<span class="keyword">f</span> action=//www.baidu.<span class="keyword">com</span>/s class=fm&amp;gt; &amp;<span class="keyword">lt</span>;<span class="built_in">input</span> <span class="built_in">type</span>=hidden name=bdorz_come value=<span class="number">1</span>&amp;gt; &amp;<span class="keyword">lt</span>;<span class="built_in">input</span> <span class="built_in">type</span>=hidden name=ie value=utf-<span class="number">8</span>&amp;gt; &amp;<span class="keyword">lt</span>;<span class="built_in">input</span> <span class="built_in">type</span>=hidden name=<span class="keyword">f</span> value=<span class="number">8</span>&amp;gt; &amp;<span class="keyword">lt</span>;<span class="built_in">input</span> <span class="built_in">type</span>=hidden name=rsv_bp value=<span class="number">1</span>&amp;gt; &amp;<span class="keyword">lt</span>;<span class="built_in">input</span> <span class="built_in">type</span>=hidden name=rsv_idx value=<span class="number">1</span>&amp;gt; &amp;<span class="keyword">lt</span>;<span class="built_in">input</span> <span class="built_in">type</span>=hidden name=<span class="keyword">tn</span> value=baidu&amp;gt;&amp;<span class="keyword">lt</span>;span class=<span class="string">&quot;bg s_ipt_wr&quot;</span>&amp;gt;&amp;<span class="keyword">lt</span>;<span class="built_in">input</span> id=kw name=wd class=s_ipt value maxlength=<span class="number">255</span> autocomplete=off autofocus=autofocus&amp;gt;&amp;<span class="keyword">lt</span>;/span&amp;gt;&amp;<span class="keyword">lt</span>;span class=<span class="string">&quot;bg s_btn_wr&quot;</span>&amp;gt;&amp;<span class="keyword">lt</span>;<span class="built_in">input</span> <span class="built_in">type</span>=submit id=su value=百度一下 class=<span class="string">&quot;bg s_btn&quot;</span> autofocus&amp;gt;&amp;<span class="keyword">lt</span>;/span&amp;gt; &amp;<span class="keyword">lt</span>;/form&amp;gt; &amp;<span class="keyword">lt</span>;/div&amp;gt; &amp;<span class="keyword">lt</span>;/div&amp;gt; &amp;<span class="keyword">lt</span>;div id=u1&amp;gt; &amp;<span class="keyword">lt</span>;<span class="keyword">a</span> href=http://news.baidu.<span class="keyword">com</span> name=tj_trnews class=mnav&amp;gt;新闻&amp;<span class="keyword">lt</span>;/<span class="keyword">a</span>&amp;gt; &amp;<span class="keyword">lt</span>;<span class="keyword">a</span> href=https://www.hao123.<span class="keyword">com</span> name=tj_trhao123 class=mnav&amp;gt;hao123&amp;<span class="keyword">lt</span>;/<span class="keyword">a</span>&amp;gt; &amp;<span class="keyword">lt</span>;<span class="keyword">a</span> href=http://<span class="keyword">map</span>.baidu.<span class="keyword">com</span> name=tj_trmap class=mnav&amp;gt;地图&amp;<span class="keyword">lt</span>;/<span class="keyword">a</span>&amp;gt; &amp;<span class="keyword">lt</span>;<span class="keyword">a</span> href=http://v.baidu.<span class="keyword">com</span> name=tj_trvideo class=mnav&amp;gt;视频&amp;<span class="keyword">lt</span>;/<span class="keyword">a</span>&amp;gt; &amp;<span class="keyword">lt</span>;<span class="keyword">a</span> href=http://tieba.baidu.<span class="keyword">com</span> name=tj_trtieba class=mnav&amp;gt;贴吧&amp;<span class="keyword">lt</span>;/<span class="keyword">a</span>&amp;gt; &amp;<span class="keyword">lt</span>;noscript&amp;gt; &amp;<span class="keyword">lt</span>;<span class="keyword">a</span> href=http://www.baidu.<span class="keyword">com</span>/bdorz/login.gif?login&amp;amp;tpl=mn&amp;amp;<span class="keyword">u</span>=http%<span class="number">3</span>A%<span class="number">2</span>F%<span class="number">2</span>Fwww.baidu.<span class="keyword">com</span>%<span class="number">2</span><span class="keyword">f</span>%<span class="number">3</span>fbdorz_come%<span class="number">3</span>d1 name=tj_login class=<span class="keyword">lb</span>&amp;gt;登录&amp;<span class="keyword">lt</span>;/<span class="keyword">a</span>&amp;gt; &amp;<span class="keyword">lt</span>;/noscript&amp;gt; &amp;<span class="keyword">lt</span>;script&amp;gt;document.<span class="keyword">write</span>(<span class="string">&#x27;&amp;lt;a href=&quot;http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=&#x27;</span>+ encodeURIComponent(window.location.href+ (window.location.<span class="built_in">search</span> === <span class="string">&quot;&quot;</span> ? <span class="string">&quot;?&quot;</span> : <span class="string">&quot;&amp;&quot;</span>)+ <span class="string">&quot;bdorz_come=1&quot;</span>)+ <span class="string">&#x27;&quot; name=&quot;tj_login&quot; class=&quot;lb&quot;&amp;gt;登录&amp;lt;/a&amp;gt;&#x27;</span>);</span><br><span class="line">                &amp;<span class="keyword">lt</span>;/script&amp;gt; &amp;<span class="keyword">lt</span>;<span class="keyword">a</span> href=//www.baidu.<span class="keyword">com</span>/more/ name=tj_briicon class=bri style=<span class="string">&quot;display: block;&quot;</span>&amp;gt;更多产品&amp;<span class="keyword">lt</span>;/<span class="keyword">a</span>&amp;gt; &amp;<span class="keyword">lt</span>;/div&amp;gt; &amp;<span class="keyword">lt</span>;/div&amp;gt; &amp;<span class="keyword">lt</span>;/div&amp;gt; &amp;<span class="keyword">lt</span>;div id=ftCon&amp;gt; &amp;<span class="keyword">lt</span>;div id=ftConw&amp;gt; &amp;<span class="keyword">lt</span>;<span class="keyword">p</span> id=<span class="keyword">lh</span>&amp;gt; &amp;<span class="keyword">lt</span>;<span class="keyword">a</span> href=http://home.baidu.<span class="keyword">com</span>&amp;gt;关于百度&amp;<span class="keyword">lt</span>;/<span class="keyword">a</span>&amp;gt; &amp;<span class="keyword">lt</span>;<span class="keyword">a</span> href=http://ir.baidu.<span class="keyword">com</span>&amp;gt;About Baidu&amp;<span class="keyword">lt</span>;/<span class="keyword">a</span>&amp;gt; &amp;<span class="keyword">lt</span>;/<span class="keyword">p</span>&amp;gt; &amp;<span class="keyword">lt</span>;<span class="keyword">p</span> id=<span class="keyword">cp</span>&amp;gt;&amp;<span class="keyword">copy</span>;<span class="number">2017</span>&amp;nbsp;Baidu&amp;nbsp;&amp;<span class="keyword">lt</span>;<span class="keyword">a</span> href=http://www.baidu.<span class="keyword">com</span>/duty/&amp;gt;使用百度前必读&amp;<span class="keyword">lt</span>;/<span class="keyword">a</span>&amp;gt;&amp;nbsp; &amp;<span class="keyword">lt</span>;<span class="keyword">a</span> href=http://jianyi.baidu.<span class="keyword">com</span>/ class=<span class="keyword">cp</span>-feedback&amp;gt;意见反馈&amp;<span class="keyword">lt</span>;/<span class="keyword">a</span>&amp;gt;&amp;nbsp;京ICP证<span class="number">030173</span>号&amp;nbsp; &amp;<span class="keyword">lt</span>;img src=//www.baidu.<span class="keyword">com</span>/img/gs.gif&amp;gt; &amp;<span class="keyword">lt</span>;/<span class="keyword">p</span>&amp;gt; &amp;<span class="keyword">lt</span>;/div&amp;gt; &amp;<span class="keyword">lt</span>;/div&amp;gt; &amp;<span class="keyword">lt</span>;/div&amp;gt; &amp;<span class="keyword">lt</span>;/body&amp;gt; &amp;<span class="keyword">lt</span>;/html&amp;gt;</span><br></pre></td></tr></table></figure>
<p>2.缓存(下载)</p>
<figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[root@litong ~]# curl -<span class="keyword">o</span> baidu.html https://www.baidu.<span class="keyword">com</span>  #将百度首页保存成html本地文件</span><br><span class="line">  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current</span><br><span class="line">                                 Dload  Upload   Total   Spent    Left  Speed</span><br><span class="line"><span class="number">100</span>  <span class="number">2443</span>  <span class="number">100</span>  <span class="number">2443</span>    <span class="number">0</span>     <span class="number">0</span>  <span class="number">10319</span>      <span class="number">0</span> --:--:-- --:--:-- --:--:-- <span class="number">10351</span></span><br><span class="line">[root@litong ~]# <span class="keyword">cat</span> baidu.html </span><br><span class="line">&amp;<span class="keyword">lt</span>;!DOCTYPE html&amp;gt;</span><br><span class="line">&amp;<span class="keyword">lt</span>;!--STATUS OK--&amp;gt;&amp;<span class="keyword">lt</span>;html&amp;gt; &amp;<span class="keyword">lt</span>;head&amp;gt;&amp;<span class="keyword">lt</span>;meta http-equiv=content-<span class="built_in">type</span> content=text/html;charset=utf-<span class="number">8</span>&amp;gt;&amp;<span class="keyword">lt</span>;meta http-equiv=<span class="keyword">X</span>-UA-Compatible content=IE=Edge&amp;gt;&amp;<span class="keyword">lt</span>;meta content=always name=referrer&amp;gt;&amp;<span class="keyword">lt</span>;link rel=stylesheet <span class="built_in">type</span>=text/css href=https://ss1.bdstatic.<span class="keyword">com</span>/<span class="number">5</span>eN1bjq8AAUYm2zgoY3K/r/www/cache/bdorz/baidu.<span class="built_in">min</span>.css&amp;gt;&amp;<span class="keyword">lt</span>;title&amp;gt;百度一下,你就知道&amp;<span class="keyword">lt</span>;/title&amp;gt;&amp;<span class="keyword">lt</span>;/head&amp;gt; &amp;<span class="keyword">lt</span>;body link=#<span class="number">0000</span><span class="keyword">cc</span>&amp;gt; &amp;<span class="keyword">lt</span>;div id=wrapper&amp;gt; &amp;<span class="keyword">lt</span>;div id=head&amp;gt; &amp;<span class="keyword">lt</span>;div class=head_wrapper&amp;gt; &amp;<span class="keyword">lt</span>;div class=s_form&amp;gt; &amp;<span class="keyword">lt</span>;div class=s_form_wrapper&amp;gt; &amp;<span class="keyword">lt</span>;div id=<span class="keyword">lg</span>&amp;gt; &amp;<span class="keyword">lt</span>;img hidefocus=true src=//www.baidu.<span class="keyword">com</span>/img/bd_logo1.png width=<span class="number">270</span> height=<span class="number">129</span>&amp;gt; &amp;<span class="keyword">lt</span>;/div&amp;gt; </span><br><span class="line">... #省略片段</span><br><span class="line">[root@litong ~]# curl -<span class="keyword">o</span> Python-<span class="number">3.5</span>.<span class="number">5</span>.tgz https://www.<span class="keyword">python</span>.org/ftp/<span class="keyword">python</span>/<span class="number">3.5</span>.<span class="number">5</span>/Python-<span class="number">3.5</span>.<span class="number">5</span>.tgz  #替换wget命令下载Python,断点续传-C</span><br><span class="line">  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current</span><br><span class="line">                                 Dload  Upload   Total   Spent    Left  Speed</span><br><span class="line"><span class="number">100</span> <span class="number">19.8</span>M  <span class="number">100</span> <span class="number">19.8</span>M    <span class="number">0</span>     <span class="number">0</span>  <span class="number">29.0</span>M      <span class="number">0</span> --:--:-- --:--:-- --:--:-- <span class="number">29.0</span>M</span><br><span class="line">[root@litong ~]# <span class="keyword">ll</span> | <span class="keyword">grep</span> Python</span><br><span class="line">-rw-r--r-- <span class="number">1</span> root root <span class="number">20766931</span> May <span class="number">22</span> <span class="number">17</span>:<span class="number">38</span> Python-<span class="number">3.5</span>.<span class="number">5</span>.tgz</span><br></pre></td></tr></table></figure>
<p>3.请求方式设置  </p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@litong ~]# curl -H &quot;Content-Type:application/json&quot; -X POST -d &#x27;&#123; &quot;arg&quot;: 125086 &#125;&#x27; http://47.67.44.121:9130/learning-path/tree/queryPhaseAndSubject  #以json的方式进行请求</span><br><span class="line">% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current</span><br><span class="line">                                Dload  Upload   Total   Spent    Left  Speed</span><br><span class="line">100   231    0   214  100    17    214     17  0:00:01 --:--:--  0:00:01 14437</span><br><span class="line">&#123;&quot;message&quot;:null,&quot;result&quot;:&quot;success&quot;,&quot;data&quot;:[&#123;&quot;subjectId&quot;:&quot;4267aa39-6ecb-40b7-8e10-7b309d022aec&quot;,&quot;subjectName&quot;:&quot;语文&quot;,&quot;phaseId&quot;:&quot;c7241629-1ec4-4035-b04c-ef17f7866688&quot;,&quot;phaseName&quot;:&quot;高中&quot;&#125;],&quot;code&quot;:0,&quot;success&quot;:true&#125;</span><br></pre></td></tr></table></figure>
<p>4.设置referer</p>
<figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@litong ~]# curl --referer http://www.google.<span class="keyword">com</span> http://www.baidu.<span class="keyword">com</span> </span><br></pre></td></tr></table></figure>

<p>5.设置User-Agent </p>
<figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@litong ~]# curl -A <span class="string">&quot;Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36&quot;</span> http://www.baidu.<span class="keyword">com</span> </span><br></pre></td></tr></table></figure>
<p>6.设置cookie</p>
<figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@litong ~]# curl  --cookie <span class="string">&quot;user=litong&quot;</span> http://www.baidu.<span class="keyword">com</span> </span><br></pre></td></tr></table></figure>
<p>7.设置请求头</p>
<figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@litong ~]# curl  -H <span class="string">&quot;accept-language:zh-cn&quot;</span> http://www.baidu.<span class="keyword">com</span> </span><br></pre></td></tr></table></figure>
<p>8.进行认证</p>
<figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">[root@litong ~]# curl  -<span class="keyword">u</span> liton<span class="variable">g:0517108</span> http://www.gitlab.<span class="keyword">com</span>/users/sign_in</span><br><span class="line">  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current</span><br><span class="line">                                 Dload  Upload   Total   Spent    Left  Speed</span><br><span class="line">  <span class="number">0</span>     <span class="number">0</span>    <span class="number">0</span>     <span class="number">0</span>    <span class="number">0</span>     <span class="number">0</span>      <span class="number">0</span>      <span class="number">0</span> --:--:-- --:--:-- --:--:--     <span class="number">0</span>&amp;<span class="keyword">lt</span>;!                                                                                                                DOCTYPE html&amp;gt;</span><br><span class="line">&amp;<span class="keyword">lt</span>;html class=<span class="string">&quot;devise-layout-html&quot;</span>&amp;gt;</span><br><span class="line">&amp;<span class="keyword">lt</span>;head prefix=<span class="string">&quot;og: http://ogp.me/ns#&quot;</span>&amp;gt;</span><br><span class="line">&amp;<span class="keyword">lt</span>;meta charset=<span class="string">&quot;utf-8&quot;</span>&amp;gt;</span><br><span class="line">&amp;<span class="keyword">lt</span>;meta content=<span class="string">&quot;IE=edge&quot;</span> http-equiv=<span class="string">&quot;X-UA-Compatible&quot;</span>&amp;gt;</span><br><span class="line">&amp;<span class="keyword">lt</span>;meta content=<span class="string">&quot;object&quot;</span> property=<span class="string">&quot;og:type&quot;</span>&amp;gt;</span><br><span class="line">&amp;<span class="keyword">lt</span>;meta content=<span class="string">&quot;GitLab&quot;</span> property=<span class="string">&quot;og:site_name&quot;</span>&amp;gt;</span><br><span class="line">&amp;<span class="keyword">lt</span>;meta content=<span class="string">&quot;Sign in&quot;</span> property=<span class="string">&quot;og:title&quot;</span>&amp;gt;</span><br><span class="line">&amp;<span class="keyword">lt</span>;meta content=<span class="string">&quot;GitLab Community Edition&quot;</span> property=<span class="string">&quot;og:description&quot;</span>&amp;gt;</span><br><span class="line">...省略片段</span><br></pre></td></tr></table></figure>
<p>9.上传文件</p>
<figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"> [root@litong ~]# curl http://<span class="number">127.0</span>.<span class="number">0.1</span>/<span class="keyword">up</span> -F <span class="string">&quot;file=@logo.png&quot;</span></span><br><span class="line">  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current</span><br><span class="line">                                 Dload  Upload   Total   Spent    Left  Speed</span><br><span class="line"><span class="number">100</span>  <span class="number">4616</span>    <span class="number">0</span>    <span class="number">76</span>  <span class="number">100</span>  <span class="number">4540</span>     <span class="number">76</span>   <span class="number">4540</span>  <span class="number">0</span>:<span class="number">00</span>:<span class="number">01</span> --:--:--  <span class="number">0</span>:<span class="number">00</span>:<span class="number">01</span>  <span class="number">8213</span>&#123;<span class="string">&quot;hash&quot;</span>:<span class="string">&quot;FmP639IPMcunQpiXidRPNisi2lDp&quot;</span>,<span class="string">&quot;key&quot;</span>:<span class="string">&quot;FmP639IPMcunQpiXidRPNisi2lDp&quot;</span>&#125;</span><br></pre></td></tr></table></figure></section>
    <!-- Tags START -->
    
      <div class="tags">
        <span>Tags:</span>
        
  <a href="/tags#Linux" >
    <span class="tag-code">Linux</span>
  </a>

      </div>
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/2018/05/18/%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B8%80%E4%B8%AASpring%20Boot%20Starter/">
        <span class="nav-arrow">← </span>
        
          自定义一个Spring Boot Starter
        
      </a>
    
    
      <a class="nav-right" href="/2018/05/22/Linux%E5%9F%BA%E7%A1%80-%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%B9%8B%E4%B8%89%E5%89%91%E5%AE%A2/">
        
          Linux基础-正则表达式之三剑客
        
        <span class="nav-arrow"> →</span>
      </a>
    
  </div>

    <!-- NAV END -->
    <!-- 打赏 START -->
    
      <div class="money-like">
        <div class="reward-btn">
          赏
          <span class="money-code">
            <span class="alipay-code">
              <div class="code-image"></div>
              <b>使用支付宝打赏</b>
            </span>
            <span class="wechat-code">
              <div class="code-image"></div>
              <b>使用微信打赏</b>
            </span>
          </span>
        </div>
        <p class="notice">若你觉得我的文章对你有帮助，欢迎点击上方按钮对我打赏</p>
      </div>
    
    <!-- 打赏 END -->
    <!-- 二维码 START -->
    
      <div class="qrcode">
        <canvas id="share-qrcode"></canvas>
        <p class="notice">扫描二维码，分享此文章</p>
      </div>
    
    <!-- 二维码 END -->
    
      <!-- Utterances START -->
      <div id="utterances"></div>
      <script src="https://utteranc.es/client.js"
        repo="ltyeamin/blogtalks"
        issue-term="pathname"
        theme="github-light"
        crossorigin="anonymous"
        async></script>    
      <!-- Utterances END -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
    <aside class="catalog-container">
  <div class="toc-main">
    <strong class="toc-title">Catalog</strong>
    
      <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#Linux%E7%B3%BB%E7%BB%9F%E4%B8%8B%E7%9A%84%E4%B8%8B%E8%BD%BD%E5%B7%A5%E5%85%B7"><span class="toc-nav-text">Linux系统下的下载工具</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#%E5%91%BD%E4%BB%A4%E9%80%89%E9%A1%B9"><span class="toc-nav-text">命令选项</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#%E5%8F%82%E8%80%83%E7%A4%BA%E4%BE%8B"><span class="toc-nav-text">参考示例</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#%E6%B5%8B%E8%AF%95%E6%8E%A5%E5%8F%A3%E5%B8%B8%E7%94%A8%E7%9A%84curl"><span class="toc-nav-text">测试接口常用的curl</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#%E5%8F%82%E8%80%83%E7%A4%BA%E4%BE%8B-1"><span class="toc-nav-text">参考示例</span></a></li></ol></li></ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'http://example.com/2018/05/22/Linux基础-wget与curl命令/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

    // error image
    $(".markdown-content img").on('error', function() {
      $(this).attr('src', '/css/images/error_icon.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function() {
      var src = $(this).attr('src')
      if (src !== '/css/images/error_icon.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()

        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="'+ src +'" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function() {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })
  })();
</script>


  <script>
    var qr = new QRious({
      element: document.getElementById('share-qrcode'),
      value: document.location.href
    });
  </script>






    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
  <p class="copyright">
    &copy; 2024 | Proudly powered by <a href="https://hexo.io" target="_blank">Hexo</a>
    <br>
    Theme by <a target="_blank" rel="noopener" href="https://github.com/ltyeamin">tong.li</a>
  </p>
</footer>

<script>
  function async(u, c) {
    var d = document, t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async("https://cdn.staticfile.org/fastclick/1.0.6/fastclick.min.js", function(){
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'true';
  async("https://cdn.staticfile.org/highlight.js/9.12.0/highlight.min.js", function(){
    $('figure pre').each(function(i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      hljs.configure({useBR: true});
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>
<!-- Baidu Tongji -->



<script src='https://cdn.staticfile.org/mermaid/8.11.2/mermaid.min.js'></script>



<script src="/js/script.js"></script>


  </body>
</html>